package com.wclass.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.wclass.entity.BaseDiscount;
import com.wclass.entity.BaseDiscountBill;
import com.wclass.mapper.BaseDiscountBillMapper;
import com.wclass.mapper.BaseDiscountMapper;
import com.wclass.service.IBaseDiscountBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 优惠券领取管理 服务实现类
 * </p>
 *
 * @author SEN
 * @since 2019-02-25
 */
@Service
public class BaseDiscountBillServiceImpl extends ServiceImpl<BaseDiscountBillMapper, BaseDiscountBill> implements IBaseDiscountBillService {

    @Autowired
    private BaseDiscountMapper baseDiscountMapper;

    @Override
    public void insertInfo(BaseDiscount discount, Long userID) {
        BaseDiscountBill info = new BaseDiscountBill();
        info.setCrtTime(new Date());
        info.setDiscountId(discount.getId());
        info.setAmount(discount.getAmount());
        info.setCourseId(discount.getCourseId());
        info.setStartTime(discount.getStartTime());
        info.setExpireTime(discount.getExpireTime());
        info.setState(0);
        info.setUserId(userID);
        baseMapper.insert(info);

        discount.setNumberDraw(discount.getNumberDraw() + 1);
        baseDiscountMapper.updateById(discount);

    }
}
